package cn.edu.swpu.cins.u_chain.frontend.controller.user;

import cn.edu.swpu.cins.u_chain.Exception.user.TeacherException;
import cn.edu.swpu.cins.u_chain.Exception.user.UserException;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.ResultData;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.user.teacher.TeacherDetail;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.user.teacher.TeacherInfo;
import cn.edu.swpu.cins.u_chain.frontend.service.user.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;

@RestController
@RequestMapping("UChain/user/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    //@ExceptionHandler({TeacherException.class, SQLException.class, RuntimeException.class})
    public ResultData handleException(Exception e) {
        return new ResultData(false, e.getMessage());
    }

    @PostMapping("addInfo")
    public ResultData addTeacherInfo(@RequestBody TeacherInfo teacherInfo) {
        teacherService.addTeacherInfo(teacherInfo);
        return new ResultData(true, "添加信息成功");
    }

    @GetMapping("getInfo")
    public ResultData getTeacherInfo(@RequestParam int userId) {
        TeacherDetail detail = teacherService.selectDetail(userId);
        return new ResultData(true, "老师资料", detail);
    }
}
